<?php
// +----------------------------------------------------------------------
// | Author: July
// +----------------------------------------------------------------------
// | 创建时间: 2023-12-27 20:39:42
// +----------------------------------------------------------------------
// | 数据库管理模型
// +----------------------------------------------------------------------

namespace july\julyadmin\common\model;

use think\Model;

class DatabaseManage extends Model
{
    //主键
    protected $pk = 'id';
    //设置自动时间写入类型
    protected $autoWriteTimestamp = false;

    /**
     * 删除数据后，先删除数据表
     * @Author   July
     * @DateTime 2024-01-13T20:17:15+0800
     * @param    array                   $data 当前记录信息
     */
    public static function onAfterDelete($data)
    {
        \think\facade\Db::query("DROP TABLE IF EXISTS {$data['name']}");
    }

    //允许出现长度的类型
    const ALLOW_USE_LENGTH_TYPES = [
        'tinyint'    => 'tinyint',
        'smallint'   => 'smallint',
        'mediumint'  => 'mediumint',
        'int'        => 'int',
        'bigint'     => 'bigint',
        'float'      => 'float',
        'double'     => 'double',
        'decimal'    => 'decimal',
        'char'       => 'chart',
        'varchar'    => 'varchar',
        'tinytext'   => 'tinytext',
        'text'       => 'text',
        'mediumtext' => 'mediumtext',
        'binary'     => 'binary',
        'varbinary'  => 'varbinary',
    ];
    //支持的字段类型
    const TYPES = [
        'tinyint'    => 'tinyint',
        'smallint'   => 'smallint',
        'mediumint'  => 'mediumint',
        'int'        => 'int',
        'bigint'     => 'bigint',
        'float'      => 'float',
        'double'     => 'double',
        'decimal'    => 'decimal',
        'char'       => 'chart',
        'varchar'    => 'varchar',
        'tinytext'   => 'tinytext',
        'text'       => 'text',
        'mediumtext' => 'mediumtext',
        'longtext'   => 'longtext',
        'binary'     => 'binary',
        'varbinary'  => 'varbinary',
        'tinyblob'   => 'tinyblob',
        'longblob'   => 'longblob',
        'blob'       => 'blob',
        'mediumblob' => 'mediumblob',
        'date'       => 'date',
        'time'       => 'time',
        'datetime'   => 'datetime',
        'timestamp'  => 'timestamp',
        'json'       => 'json',
    ];
}
